from flask import Blueprint,request,jsonify
from utils.getdata import getdata
from utils.xtree import xtree
from utils.mydb import db1
from utils.myredis import myredis
from utils.acl import acl
from utils.mytoken import token1

bp_acl = Blueprint("bp_acl",__name__)



@bp_acl.route("/login")
def login():
    user = request.args.get("user")
    pwd = request.args.get("pwd")
    sql = "select * from users where name='%s'and password='%s'"%(user,pwd)
    res = db1.find(sql)
    if res:
        vurl = acl.get_page_reslist(res["id"])
        key = "interface"+str(res["id"])
        myredis().insert_values(key,vurl)
        token = token1.encode_jwt(int(res["id"]),60*60,"123")
        return jsonify({"code":200,"userid":res["id"],"token":token,"vurl":vurl})
    else:
        return jsonify({"code":400,"msg":'login fail'})